package cn.com.bdqn.controller;

import cn.com.bdqn.entity.CstActivity;
import cn.com.bdqn.service.CstActivityService;
import cn.com.bdqn.utils.ReturnData;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cstActivity")
@Api(tags = "客户交往记录信息管理接口")
public class CstActivityController {

    @Autowired
    private CstActivityService cstActivityService;

    @Operation(summary = "修改客户交往记录信息")
    @PostMapping("/updateCstActivity")
    public ReturnData updateCstActivity(CstActivity cstActivity){
        int result = cstActivityService.updateCstActivity(cstActivity);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("修改客户交往记录信息异常");
        }
    }

    @Operation(summary = "新增客户交往记录信息")
    @PostMapping("/addCstActivity")
    public ReturnData addCstActivity(CstActivity cstActivity){
        int result = cstActivityService.addCstActivity(cstActivity);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("新增客户交往记录信息异常");
        }
    }

    @Operation(summary = "删除客户交往记录信息")
    @PostMapping("/delCstActivity")
    public ReturnData delCstActivity(Long atvId){
        int result = cstActivityService.delCstActivity(atvId);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("删除客户交往记录信息异常");
        }
    }

    @Operation(summary = "根据客户编号查询相应的交往记录信息")
    @PostMapping("/queryByAtvCustNo")
    public ReturnData queryByAtvCustNo(String atvCustNo){
        try {
            List<CstActivity> cstActivities = cstActivityService.queryByAtvCustNo(atvCustNo);
            return ReturnData.ok().put("cstActivities",cstActivities);
        }catch (Exception e){
            return ReturnData.error();
        }
    }

    @Operation(summary = "根据交往记录编号查询相应的交往记录信息")
    @PostMapping("/queryByAtvId")
    public ReturnData queryByAtvId(Long atvId){
        try {
            CstActivity cstActivity = cstActivityService.queryByAtvId(atvId);
            return ReturnData.ok().put("cstActivity",cstActivity);
        }catch (Exception e){
            return ReturnData.error();
        }
    }
}
